package com.tsingtree.modular.service.impl;

import com.tsingtree.modular.entity.NanGiftFieldConfig;
import com.tsingtree.modular.mapper.NanGiftFieldConfigMapper;
import com.tsingtree.modular.model.params.NanGiftFieldConfigParam;
import com.tsingtree.modular.model.result.NanGiftFieldConfigResult;
import com.tsingtree.modular.service.NanGiftFieldConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import com.tsingtree.base.pojo.page.LayuiPageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tsingtree.base.pojo.page.LayuiPageFactory;
import com.tsingtree.roses.core.util.ToolUtil;
import java.io.Serializable;

/**
 * <p>
 * 精美礼物-字段配置表 服务实现类
 * </p>
 *
 * @author jagger
 * @since 2025-10-24
 */
@Service
public class NanGiftFieldConfigServiceImpl extends ServiceImpl<NanGiftFieldConfigMapper, NanGiftFieldConfig> implements NanGiftFieldConfigService {

    @Override
    public void add(NanGiftFieldConfigParam param){
        NanGiftFieldConfig entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(NanGiftFieldConfigParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(NanGiftFieldConfigParam param){
        NanGiftFieldConfig oldEntity = getOldEntity(param);
        NanGiftFieldConfig newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public NanGiftFieldConfigResult findBySpec(NanGiftFieldConfigParam param){
        return null;
    }

    @Override
    public List<NanGiftFieldConfigResult> findListBySpec(NanGiftFieldConfigParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(NanGiftFieldConfigParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<NanGiftFieldConfig> getByActivityId(Integer activityId){
        return this.baseMapper.getByActivityId(activityId);
    }

    private Serializable getKey(NanGiftFieldConfigParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private NanGiftFieldConfig getOldEntity(NanGiftFieldConfigParam param) {
        return this.getById(getKey(param));
    }

    private NanGiftFieldConfig getEntity(NanGiftFieldConfigParam param) {
        NanGiftFieldConfig entity = new NanGiftFieldConfig();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}

